package com.itcast;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class StudentServletConfig extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletConfig config = super.getServletConfig();

        String encoding = config.getInitParameter("encoding");
        System.out.println(encoding);

        Enumeration<String> names = config.getInitParameterNames();
        while (names.hasMoreElements()) {
            String key = names.nextElement();
            String value = config.getInitParameter(key);
            System.out.println(key+","+value);
        }

        ServletContext context = config.getServletContext();
        Object username = context.getAttribute("username");
        System.out.println(username);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
